/*    */ package com.equipmentmanage.dao.impl;
/*    */ 
/*    */ import com.equipmentmanage.dao.RepairDao;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.model.Repair;
import com.equipmentmanage.util.DateUtil;
import com.equipmentmanage.util.StringUtil;

/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import javax.annotation.Resource;
/*    */ import org.springframework.jdbc.core.JdbcTemplate;
/*    */ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
/*    */ 
/*    */ @Repository("repairDao")
/*    */ public class RepairDaoImpl
/*    */   implements RepairDao
/*    */ {
/*    */ 
/*    */   @Resource
/*    */   private JdbcTemplate jdbcTemplate;
/*    */ 
/*    */   public void add(Repair repair)
/*    */   {
/* 33 */     String sql = "insert into t_repair values(null,?,?,null,now(),null,0,1)";
/* 34 */     this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(repair.getEquipmentId()), repair.getUserMan() });
/*    */   }
/*    */ 
/*    */   public void update(Repair repair) {
/* 38 */     String sql = "update t_repair set repairMan=?,finishTime=now(),state=?,finishState=2 where equipmentId=?";
/* 39 */     this.jdbcTemplate.update(sql, new Object[] { repair.getRepairMan(), repair.getState(), Integer.valueOf(repair.getEquipmentId()) });
/*    */   }
/*    */ 
/*    */   public List<Repair> find(PageBean pageBean, Repair s_repair) {
/* 43 */     StringBuffer sb = new StringBuffer("select * from t_repair t1,t_equipment t2 where t1.equipmentId=t2.id ");
/* 44 */     if (s_repair != null) {
/* 45 */       if (StringUtil.isNotEmpty(s_repair.getEquipmentName())) {
/* 46 */         sb.append(" and t2.name like '%" + s_repair.getEquipmentName() + "%'");
/*    */       }
/* 48 */       if (s_repair.getFinishState() != null) {
/* 49 */         sb.append(" and t1.finishState=" + s_repair.getFinishState());
/*    */       }
/*    */     }
/* 52 */     if (pageBean != null) {
/* 53 */       sb.append(" limit " + pageBean.getStart() + "," + pageBean.getPageSize());
/*    */     }
/* 55 */     final List repairList = new ArrayList();
/* 56 */     this.jdbcTemplate.query(sb.toString(), new Object[0], new RowCallbackHandler()
/*    */     {
/*    */       public void processRow(ResultSet rs) throws SQLException
/*    */       {
/* 60 */         Repair repair = new Repair();
/* 61 */         repair.setId(Integer.valueOf(rs.getInt("id")));
/* 62 */         repair.setEquipmentId(rs.getInt("equipmentId"));
/* 63 */         repair.setEquipmentName(rs.getString("name"));
/* 64 */         repair.setEquipmentNo(rs.getString("no"));
/* 65 */         repair.setUserMan(rs.getString("userMan"));
/* 66 */         repair.setRepairMan(rs.getString("repairMan"));
/* 67 */         repair.setRepairTime(DateUtil.formatString(rs.getString("repairTime"), "yyyy-MM-dd HH:mm:ss"));
/* 68 */         repair.setFinishTime(DateUtil.formatString(rs.getString("finishTime"), "yyyy-MM-dd HH:mm:ss"));
/* 69 */         repair.setState(Integer.valueOf(rs.getInt("state")));
/* 70 */         repairList.add(repair);
/*    */       }
/*    */     });
/* 73 */     return repairList;
/*    */   }
/*    */ 
/*    */   public int count(Repair s_repair) {
/* 77 */     StringBuffer sb = new StringBuffer("select count(*) from t_repair t1,t_equipment t2 where t1.equipmentId=t2.id ");
/* 78 */     if (s_repair != null) {
/* 79 */       if (StringUtil.isNotEmpty(s_repair.getEquipmentName())) {
/* 80 */         sb.append(" and t2.name like '%" + s_repair.getEquipmentName() + "%'");
/*    */       }
/* 82 */       if (s_repair.getFinishState() != null) {
/* 83 */         sb.append(" and t1.finishState=" + s_repair.getFinishState());
/*    */       }
/*    */     }
/* 86 */     return ((Integer)this.jdbcTemplate.queryForObject(sb.toString(), Integer.class)).intValue();
/*    */   }
/*    */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.dao.impl.RepairDaoImpl
 * JD-Core Version:    0.6.1
 */